﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataLevel;

namespace LogicLevel
{
    public class UserMethod
    {
        static public int userRegister(String email, String username, String password)
        {
            return UserDataAccess.register(email, username, password);
        }

        static public int userLogin(String email, String password)
        {
            return UserDataAccess.login(email, password);
        }

        static public int userVerify(int id, String verification)
        {
            return UserDataAccess.verify(id, verification);
        }
        static public int getUserPersonalInfo(int id, ref String nickName, ref String email, ref String image, ref String major, ref short enterYear, ref String signature)
        {
            try
            {
                account _account = UserDataAccess.getUserAccount(id);
                userinfo _userinfo = UserDataAccess.getUserInfo(id);
                if (_account.nickname != null)
                    nickName = _account.nickname;

                email = _account.Email;
                if (_userinfo.photo != null)
                    image = _userinfo.photo;
     
                if(_userinfo.major != null)
                    major = _userinfo.major;
                if(_userinfo.enteryear != null)
                    enterYear = (short)_userinfo.enteryear;
                if(_userinfo.signature != null)
                    signature = _userinfo.signature;
                return 1;
            }
            catch (Exception e)
            {
                return -1;
            }
        }
        static public int setUserPersonalInfo(int id, string nickname, string major, short enteryear, string signature)
        {
            return (UserDataAccess.setUserInfo(id, nickname, major, enteryear, signature));
           
        }
        static public int changePwd(int id, string oldpwd, string newpwd)
        {
            return (UserDataAccess.changePwd(id, oldpwd, newpwd));
        }
    }
}
